Date.prototype.stdTimezoneOffset = function() {
	var jan = new Date(this.getFullYear(), 0, 1);
	var jul = new Date(this.getFullYear(), 6, 1);
	return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
}
Date.prototype.dst = function() {
	return this.getTimezoneOffset() < this.stdTimezoneOffset();
}
Date.prototype.getTimezone = function() {
	var tz = this.getTimezoneOffset() / 60;
	return (this.dst) ? tz : tz;
}

String.prototype.nl2br = function() {
	return (this + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br />$2');
}
function nl2br(str) {   
	return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br />$2');
}

/**
 * facebook UI Object
 * 
 */
var fbUI = {
    message: {unread: 0, all: 0},
	scope: {scope:'email,user_location'},
	//facebook login
    login: function(url) {
        FB.login(function(response) {
			//_push({"key":"fblogin", "val":response});
			if (response.authResponse) {
				FB.api('/me?fields=id,name,location,gender,picture,email', function(resp) {
					$.post(url, resp, function(data) {
						var json = wpu.parseJSON(data);
						if (json.head == 'E') {
							alert(json.data);
						} else location.href = json.data.href;
					});
				});
			}
        }, this.scope);
    },
	//invite friends: apprequests
	invite: function(title, message) {
		FB.login(function(response) {
			if (response.authResponse) {
				// user successfully logged in 
				FB.ui({
					method:'apprequests', link:'http://www.yawii.com',
					title:title, message:message
				}, function (response) {
					_push({"key":"fbinvite", "val":response});
				});
			}
		}, this.scope);
	},
	//recommend url: method=feed, send
	recommend: function(url, method, callback) {
		FB.login(function(response) {
			if (response.authResponse) {
				FB.ui({
					method:method, link:url
				}, function (response) {
					callback(response);
				});
			}
		}, this.scope);
	},
	share: function(url) {
		window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(url), 'Share', 'toolbar=0, menubar=0, width=640, height=320');
	}
};

var wForm = {
	validateResult: function(json) {
		if (json.success) {
			alert(json.success);
		} else {
			for (var name in json) {
				$('#'+name).focus();
				return;
			}
		}
	}
};

// loading if document ready
$(function() {
	//set watermake
	$('.enablewatermake').watermark('watermark');
	//set close icon
	$('.icon-close').click(function(){
		$(this).parent().hide();
	});
	//set sidebar toggle
	$('.widget-sidebar > .title').click(function() {
		$(this).parent().toggleClass('closed');
	});
	//set countdown
	$('[rel=tipsy]').tipsy({live: true, gravity:'s'});
});